<?php
namespace App\Models\SalesReportLT;

use Illuminate\Database\Eloquent\Model;

class PaymentClassify extends Model
{
    protected $table = 'lt_sr_payment_classify';

    protected $guarded = [];

    public $timestamps = false;

    public static $_type = [
        1 => '数值',
        2 => '占比',
    ];
    //核算月报，制成汇总报表时统一字段赋值
    public static function _getData($rateOdds,$pd): array
    {
        return [
            'rate_odds' => $rateOdds,
            'sales_volume' => $pd->sales_volume,
            'sales_amount_rmb' => $pd->sales_amount_rmb,
            'refund_num' => $pd->refund_num,
            'refund_amount_rmb' => $pd->refund_amount_rmb,
            'thfba_rmb' => $pd->thfba_rmb,
            't_purchase_price_rmb' => $pd->t_purchase_price_rmb,
            't_shipment_price_rmb' => $pd->t_shipment_price_rmb,
            'other_fee_rmb' => $pd->other_fee_rmb,
            'system_use_pc_fee_rmb' => $pd->system_use_pc_fee_rmb,
            'system_use_sp_fee_rmb' => $pd->system_use_sp_fee_rmb,
            'system_use_c_fee_rmb' => $pd->system_use_c_fee_rmb,
            'super_membership_rewards_fee_rmb' => $pd->super_membership_rewards_fee_rmb,
            'super_membership_system_use_fee_rmb' => $pd->super_membership_system_use_fee_rmb,
            'super_membership_selling_fee_rmb' => $pd->super_membership_selling_fee_rmb,
            'super_membership_selling_re_fee_rmb' => $pd->super_membership_selling_re_fee_rmb,
            'integral_pc_fee_rmb' => $pd->integral_pc_fee_rmb,
            'integral_sp_fee_rmb' => $pd->integral_sp_fee_rmb,
            'rakuten_pay_use_fee_rmb' => $pd->rakuten_pay_use_fee_rmb,
            'rakuten_pay_visa_fee_rmb' => $pd->rakuten_pay_visa_fee_rmb,
            'service_fee_rmb' => $pd->service_fee_rmb,
            'spend_rmb' => $pd->spend_rmb,
            'reimburse_rmb' => $pd->reimburse_rmb,
            'reimburse_os_rmb' => $pd->reimburse_os_rmb,
            'reimburse_profit_rmb' => $pd->reimburse_profit_rmb,
            'earning_rmb' => $pd->earning_rmb,
            'total_rmb' => $pd->total_rmb,
            'profit_rmb' => $pd->profit_rmb,
        ];
    }

    public static function _getFields($headers,$groupByArr): string
    {
        $re = '';
        foreach ($headers as $field => $item){
            if('purchase_price_rmb' == $field)continue;
            if($item['sumField']){
                $re .= 'sum('.$field.') as '.$field.',';
            }
        }
        return $re.implode(',',$groupByArr);
    }
}
